package com.xc.ksxt.service;

import java.io.IOException;
import java.lang.reflect.Field;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.jooq.DSLContext;
import org.jooq.Record;
import org.jooq.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ejlchina.data.TypeRef;
import com.ejlchina.okhttps.HTTP;
import com.ejlchina.okhttps.HttpResult;
import com.ejlchina.okhttps.HttpResult.Body;
import com.ejlchina.okhttps.OkHttps;
import com.ejlchina.okhttps.fastjson.FastjsonMsgConvertor;
import com.xc.db.tables.ChoiceCopy;
import com.xc.db.tables.DateScore;
import com.xc.db.tables.QuestionCopy;
import com.xc.sys.service.SysUserService;

import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;

@Service
public class TaskJobService{
	@Autowired
	private DSLContext dsl;
	@Autowired
	private SysUserService sysUserService;
	@Autowired
	private PaperCopyService paperCopyService;
	@Autowired
	private QuestionCopyService questionCopyService;
	@Autowired
	private ChoiceCopyService choiceCopyService;
	@Autowired
	private DateScoreService dateScoreService;
	private ChoiceCopy CHOICECOPYTB = ChoiceCopy.CHOICE_COPY.as("CHOICECOPYTB");
	private QuestionCopy QUESTIONCOPYTB = QuestionCopy.QUESTION_COPY.as("QUESTIONCOPYTB");
	private DateScore DATESCORETB = DateScore.DATE_SCORE.as("DATESCORETB");
	/**
	 * 
	 * @描述: 如果用户删除了，将其他关联表的记录也删除
	 * @作者 coin
	 * @时间 2022年6月13日
	 */
	@Transactional
	@Scheduled(cron="0/59 * * * * ?")
	public void clearDb() {
//		dsl.fetch("delete from paper_user p where not exists(select id from sys_user where id=p.user_id)");
//		dsl.fetch("delete from paper_copy p where not exists(select id from sys_user where id=p.create_user_id)");
//		dsl.fetch("delete from question_copy p where not exists(select id from paper_copy where id=p.paper_copy_id)");
//		dsl.fetch("delete from choice_copy p where not exists(select id from question_copy where id=p.question_copy_id)");
//		dsl.fetch("delete from date_score p where not exists(select id from sys_user where id=p.user_id)");
	}

}
